package com.example.wifidirect;

import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.WifiP2pManager.ActionListener;
import android.net.wifi.p2p.WifiP2pManager.Channel;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;


public class WifiDirectMethods {

	 private  WifiP2pManager manager = MainActivity.manager;
	 private  Channel channel = MainActivity.channel;
	 private  MainActivity activity;
	  
	public  void connect(WifiP2pConfig config) {
        manager.connect(channel, config, new ActionListener() {
            @Override
            public void onSuccess() {
            	Message msg = new Message();
            	msg.what = 0x12;
            	activity.mHandler.sendMessage(msg);
            	Log.d("WifiDirect", "Connected");
            }
            @Override
            public void onFailure(int reason) {
                Toast.makeText(activity, "Connect failed. Retry.",
                        Toast.LENGTH_SHORT).show();
            }
        });
    }
	
	public void disconnect() {
     //   final DeviceDetailFragment fragment = (DeviceDetailFragment) getFragmentManager()
      //          .findFragmentById(R.id.frag_detail);
     //   fragment.resetViews();
        manager.removeGroup(channel, new ActionListener() {
            @Override
            public void onFailure(int reasonCode) {
                Log.d("WifiDirect", "Disconnect failed. Reason :" + reasonCode);
            }
            @Override
            public void onSuccess() {
             //   fragment.getView().setVisibility(View.GONE);
            }
        });
    }
}
